<template>
	<view class="content">
		<view class="toububjt" style="background-image: url('/static/image/shop/tixian.png');">
			<view class="xiaobtext">可提现金额（元）</view>
			<view class="margin_top2 dbaitext">￥{{price}}</view>
		</view>
		<view class="padding">
			<view class="neirong">
				<view class="padding ffffff circle margin-top">
					<view class="text_a color_three">提现金额 (元)</view>
					<view class="flexbetween margin_top">
						<view class="flexleft" style="flex: 5;">
							<view class="">￥</view>
							<input type="digit" v-model="withdraw_price" placeholder="请输入提现金额" class="daheitext">
						</view>
						<view class="huangsetext" style="flex: 1.1;" @click="withdraw_price=price">全部提现</view>
					</view>
				</view>
				<view class="paddinglr margin_top flexbetween" v-show="activeIndexJF==2||activeIndexJF==1">
					<view class="name white_nowrap">真实姓名</view>
					<input class="color_ling text_a textright" type="text" placeholder="请输入真实姓名" v-model="real_name">
				</view>
				
				
				<view class="paddinglr margin_top flexbetween" v-show="activeIndexJF==1">
					<view class="name white_nowrap">授权收款微信</view>
					<view class="name white_nowrap" @click="getopenid" v-if="!openid">点击授权</view>
					<view class="name white_nowrap" @click="getopenid" v-else="openid">已授权</view>
				</view>
				<view class="paddinglr margin_top flexbetween" v-show="activeIndexJF==2">
					<view class="name white_nowrap">支付宝账号</view>
					<input class="color_ling text_a textright" type="text" placeholder="请输入支付宝账号" v-model="alipay_code">
				</view>
				<view class="padding ffffff circle margin_top">
					<view class="ffffff flexbetween" @click="changeIndexJF(1)">
						<view class="left flexcenter">
							<image src="/static/image/home/weixin.png" mode="" class="wx"></image>
							<view class="color_san text_a">微信</view>
						</view>
						<view class="right">
							<image v-if="activeIndexJF==1" src="/static/image/home/xuanzhong.png"
								style="width: 34rpx;height: 34rpx;"></image>
							<image v-if="activeIndexJF!=1" src="/static/image/home/wiexuanzhong.png"
								style="width: 34rpx;height: 34rpx;"></image>
						</view>
					</view>
					<view class="ffffff flexbetween margin_top7" @click="changeIndexJF(2)">
						<view class="left flexcenter">
							<image src="/static/image/home/zhifubao.png" mode="" class="wx"></image>
							<view class="color_san text_a">支付宝</view>
						</view>
						<view class="right">
							<image v-if="activeIndexJF==2" src="/static/image/home/xuanzhong.png"
								style="width: 34rpx;height: 34rpx;"></image>
							<image v-if="activeIndexJF!=2" src="/static/image/home/wiexuanzhong.png"
								style="width: 34rpx;height: 34rpx;"></image>
						</view>
					</view>
				</view>
				<view class="margin_top7">
					<u-parse :content="shopInfo.shop_withdraw_rule"></u-parse>
				</view>
				<view class="footer_btn tixian" @click="withdrawal">提现</view>
				<view class="text text_green jilu margin_top" @click="goWithdrawalRecord">提现记录</view>
			</view>
		</view>
		<u-modal :show="show" :title="title" :showCancelButton="true" confirmColor="RGBA(212, 139, 57, 1)"
			@confirm="confirm" @cancel="show=false"></u-modal>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				title: "您确定要提现吗？",
				activeIndexJF: 1, // 1微信 2支付宝
				price: 0, //可提现金额
				withdraw_price: "", //提现金额
				alipay_code: "", //支付宝账号
				real_name: "", //真实姓名
				shopInfo:{},
				openid:""
			}
		},
		async onLoad(options) {
			this.price = options.withdraw_price
			let res=await this.initApp()
			console.log(res);
			this.shopInfo=res.data
			// this.getopenid()
		},
		methods: {
			getopenid(){
				let that = this
				uni.login({
					provider: 'weixin',
					success: function(resp) {
						that.openid = resp.authResult.openid
					
					},
					fail: function(err) {
						console.error("？？？？？？？？？",err);
					}
				});
			},
			withdrawal() {
				if (!this.withdraw_price||Number(this.withdraw_price==0)) {
					httpRequest.toast("提现金额不能为空!");
					return false
				}
				if (Number(this.withdraw_price)>Number(this.price)) {
					httpRequest.toast("提现金额不能大于可提现金额!");
					return false
				}
				if ((this.activeIndexJF==2||this.activeIndexJF==1) && !this.real_name) {
					httpRequest.toast("真实姓名不能为空!");
					return false
				}
				if(this.activeIndexJF==2 && !this.alipay_code){
					httpRequest.toast("支付宝账号不能为空!");
					return false
				}
				
				this.show = true
			},
			confirm() {
				if(this.activeIndexJF==1){
					this.alipay_code=""
					// this.real_name=""
				}
				httpRequest.request('/api/shop.index/withdraw', 'GET', {
					withdraw_type: this.activeIndexJF, //提现方式:1=微信,2=支付宝,
					alipay_code: this.alipay_code, //支付宝账号
					real_name: this.real_name, //真实姓名
					withdraw_price: this.withdraw_price,
					openid:this.openid
				}).then(res => {
					console.log(res);
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						httpRequest.toast(res.msg);
						setTimeout(() => {
							uni.navigateBack(1)
						}, 500)
					}
					this.show = false
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			goWithdrawalRecord() { //提现记录
				uni.navigateTo({
					url: "./withdrawalRecord"
				})
			},
			changeIndexJF(type) {
				this.activeIndexJF = type
			},
		}
	}
</script>

<style lang="scss" scoped>
	view.text1 {
		font-size: 28rpx;
		text-align: center;
		font-weight: normal;
		color: #d48b39;
	}

	.methods-item {
		padding-left: 0;
		padding-right: 0;
		border-bottom: 2rpx solid #fafafa;
	}

	.methods-item:last-child {
		border-bottom: 0;
	}

	.wx {
		width: 36rpx;
		height: 36rpx;
		background-size: 100% 100%;
		margin-right: 4rpx;
		margin-left: 4rpx;
	}

	.tixian {
		margin-top: 100rpx;
	}

	.jilu {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FD463E;
	}

	.circle {
		border-radius: 32rpx 24rpx 43rpx 42rpx;
	}

	.huangsetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FD463E;
	}

	.neirong {
		position: relative;
		top: -140rpx;
	}

	.dbaitext {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
	}

	.xiaobtext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
	}

	.toububjt {
		background-size: 100% 100%;
		width: 100%;
		padding: 20rpx 30rpx 0;
		height: 258rpx;
		box-sizing: border-box;
	}

	.daheitext {
		font-size: 40rpx;
		font-family: DIN Next LT Pro-Regular, DIN Next LT Pro;
		font-weight: 400;
		color: #333333;
	}

	.footer_btn {
		font-size: 32rpx;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		padding: 20rpx 20rpx;
		background-color: rgba(243, 39, 28, 1);
		border-radius: 64rpx;
	}

	.wx {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		margin-right: 10rpx;
	}
</style>